<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<lv-form [formGroup]="formGroup" class="formGroup main-container" lvKeepRequiredWidth>
    <lv-form-item>
        <lv-form-label>
            {{'protection_restore_to_label' | i18n}}
        </lv-form-label>
        <lv-form-control>
            <lv-radio-group formControlName="restoreTo" [lvGroupName]="'restoreToGroup'">
                <lv-group [lvGutter]="'24px'">
                    <lv-radio [lvValue]="restoreLocationType.ORIGIN" [lvDisabled]="restoreToNewLocationOnly"
                        [lv-tooltip]="restoreToNewLocationOnly ? ('protection_cloud_origin_restore_disabled_label' | i18n) : ''">
                        {{'common_restore_to_origin_location_label' | i18n}}
                    </lv-radio>
                    <lv-radio [lvValue]="restoreLocationType.NEW">
                        {{'common_restore_to_new_location_label' | i18n}}
                    </lv-radio>
                    <lv-radio [lvValue]="restoreLocationType.NATIVE" *ngIf="false">
                        {{'protection_specified_file_system_label' | i18n}}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
    <lv-form-item>
        <lv-form-label [lvRequired]="formGroup.value.restoreTo !== restoreLocationType.ORIGIN">
            {{ (formGroup.value.restoreTo === restoreLocationType.ORIGIN ? 'common_location_label' :
            'common_target_to_cluster_label') | i18n}}
        </lv-form-label>
        <lv-form-control [lvErrorTip]="baseUtilService.requiredErrorTip">
            <lv-select [lvOptions]='hostOptions' lvValueKey='key' formControlName='location' lvShowFilter
                lvFilterKey='label' lvFilterMode='contains'
                [lvDisabled]="formGroup.value.restoreTo === restoreLocationType.ORIGIN"
                (ngModelChange)='hostChange($event)'>
            </lv-select>
        </lv-form-control>
    </lv-form-item>
    <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.NEW">
        <lv-form-item>
            <lv-form-label lvRequired>
                {{'common_path_label' | i18n}}
            </lv-form-label>
            <lv-form-control class="control-container">
                <div class="tree-container">
                    <lv-tree [lvData]='filesData' #tree lvSelectionMode='single' lvSelectionAssociate="false"
                        [(lvSelection)]='fileSelection' (lvSelectionChange)="selectionChange()"
                        (lvExpandedChange)="expandedChange($event)" (lvCheck)="nodeCheck($event)" lvShowContentIcon
                        lvShowLine lvAsync lvVirtualScroll [lvNodeTemplate]='nodeTpl'>
                    </lv-tree>
                    <ng-template #nodeTpl let-item>
                        <div style="width: 400px;" lv-overflow>
                            <span *ngIf="!item.isMoreBtn">
                                <i lv-icon="{{item.contentToggleIcon}}"></i>
                                {{item.label}}
                            </span>
                        </div>
                        <span class="aui-link" *ngIf="item.isMoreBtn"
                            (click)="getResource(item.parent,item.startPage)">{{item.label}}</span>
                    </ng-template>
                </div>
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <ng-container *ngIf="formGroup.value.restoreTo === restoreLocationType.NATIVE">
        <lv-form-item>
            <lv-form-label lvRequired>
                {{'protection_new_fileset_name_label' | i18n}}
            </lv-form-label>
            <lv-form-control [lvErrorTip]="filesetNameErrorTip">
                <input lv-input type="text" formControlName="new_fileset_name" />
            </lv-form-control>
        </lv-form-item>
    </ng-container>
    <lv-form-item>
        <lv-form-label>
            {{'common_select_label' | i18n}}
        </lv-form-label>
        <lv-form-control>
            <lv-radio-group formControlName="originalType">
                <lv-group [lvGutter]="'20px'" lvDirection='vertical' class="restore-options">
                    <lv-radio [lvValue]="filesetReplaceOptions.Skip">
                        {{'protection_skip_label' | i18n}}
                    </lv-radio>
                    <lv-radio [lvValue]="filesetReplaceOptions.Overwrite">
                        {{'protection_overwrite_label' | i18n}}
                    </lv-radio>
                </lv-group>
            </lv-radio-group>
        </lv-form-control>
    </lv-form-item>
</lv-form>

<div class="aui-gutter-column-lg "></div>
<lv-collapse [lvMultiExpansion]="false" lvType="simple">
    <lv-collapse-panel [lvTitle]="titleTpl" [lvExpanded]="false">
        <lv-form [formGroup]="formGroup">
            <lv-form-item>
                <lv-form-label>
                    {{'protection_vmware_capacity_threshold_label' | i18n}}
                    <i lv-icon="aui-icon-help" [lv-tooltip]="capacityThresholdToolTip" lvTooltipPosition="rightTop"
                        lvTooltipTheme="light" class="configform-constraint" lvColorState='true'></i>
                </lv-form-label>
                <lv-form-control [lvErrorTip]="capacityThresholdErrorTip">
                    <lv-group lvGutter='8px' class="lv-group-flex-start">
                        <input lv-input formControlName="available_capacity_threshold" type="text"
                            placeholder="1-100" />
                        <span class="configform-constraint">%</span>
                    </lv-group>
                </lv-form-control>
            </lv-form-item>
        </lv-form>
    </lv-collapse-panel>
</lv-collapse>

<ng-template #titleTpl>
    <span class="aui-h3">{{'common_advanced_label'|i18n}}</span>
</ng-template>